<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <h2>后台管理界面</h2>
        <p>欢迎您：{{ userInfo.username }}</p>

        <table>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
    <script>
         new Vue({
            el: '#app',
            data: {
               userInfo: {}
            },
            mounted(){
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"))

                // axios拦截所有请求，在请求头中添加token
                axios.interceptors.request.use(config => {
                    config.headers.Authorization = this.userInfo.token
                    return config
                })

                this.getStudentList()
            },
            methods: {
                async getStudentList(){
                    const {data:res} = await axios.get('http://localhost:8080/students')
                    console.log(res)
                }
            }
        })
    </script>
</body>
</html>